<?php

namespace App\Models;

use App\Traits\HasDateTimeFormatter;
use App\Traits\Ownable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LoanTag extends Model
{
    use HasFactory, HasDateTimeFormatter, Ownable;

    protected $table = "loan_tag";

    protected $casts =[
        'user_id' => 'integer',
        'share_for_sub' => 'integer',
    ];


    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function loans()
    {
        return $this->belongsToMany(LoanApplication::class, 'loan_application_tag', 'tag_id', 'loan_id');
    }

    /**
     * 所属用户
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user() {
        return $this->belongsTo(User::class, 'user_id');
    }


    /**
     * 所属机构
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function org() {
        return $this->hasOne(Org::class, 'org_code', 'org_code');
    }
}
